/**
 * 防止抖动
 * @param fn 抖动函数
 * @param delay 延迟时间
 * @returns {(function(): void)|*}
 */
export function debounce(fn, delay = 300) {
  let timer = null;
  return function () {
    // eslint-disable-next-line consistent-this
    const context = this;
    let args = arguments;
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      timer = null;
      fn.apply(context, args);
    }, delay);
  };
}
